home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / util / cli / iuw_clitools.lha / src / getpubscreen.c < prev    next >
C/C++ Source or Header  |  1995-09-05  |  3KB  |  105 lines

  1. /* getpubscreen - get name of frontmost screen (if public), else default pubscreen
  2.  *
  3.  * Copyright (C) 1995 by Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software and its
  6.  * documentation for any purpose and without fee is hereby granted, provided
  7.  * that the above copyright notice appear in all copies and that both that
  8.  * copyright notice and this permission notice appear in supporting
  9.  * documentation.  This software is provided "as is" without express or
  10.  * implied warranty.
  11.  *
  12.  *  Basiert auf dem Hack von Henning Schmiedehausen (barnard@forge.erh.sub.org)
  13.  *  vom Bielefelder Meeting '92, gepostet in de.alt.binaries.amigaos:
  14.  *      Subject: Re: Bielefeld Hack #1: GetPubScreen
  15.  *      Date: Mon, 14 Sep 1992 00:52:01 GMT
  16.  *      Message-ID: <15XFr*1j0@forge.erh.sub.org>
  17.  *
  18.  * V1.0: 09/Feb/95
  19.  * V1.1: 03/Apr/95: minor cleanup
  20.  */
  21. #define THIS_PROGRAM    "getpubscreen"
  22. #define THIS_VERSION    "1.1"
  23.  
  24. #include <exec/types.h>
  25. #include <exec/libraries.h>
  26. #include <intuition/intuitionbase.h>
  27. #include <intuition/screens.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30.  
  31. #define SysBase_DECLARED
  32. #include <proto/exec.h>
  33. #include <proto/dos.h>
  34. #define IntuitionBase_DECLARED
  35. #include <proto/intuition.h>
  36.  
  37. extern struct Library *         SysBase;
  38. extern struct IntuitionBase *   IntuitionBase;
  39.  
  40. static const char amiga_version[] = "\0$VER: " THIS_PROGRAM " " THIS_VERSION " (" __COMMODORE_DATE__ ")";
  41.  
  42. const char Template[] = "DEFAULT/S";
  43. __aligned struct {
  44.     LONG    def;
  45. } Args;
  46.  
  47.  
  48. void
  49. _main()
  50. {
  51.     struct RDArgs *rdargs;
  52.     LONG rc = RETURN_OK;
  53.     UBYTE name[MAXPUBSCREENNAME+1];
  54.  
  55.     if( SysBase->lib_Version < 37 ) {
  56.         #define MESSAGE "requires AmigaOS 2.04 or higher\n"
  57.         Write(Output(), MESSAGE, sizeof(MESSAGE)-1);
  58.         _exit(RETURN_FAIL);
  59.         #undef MESSAGE
  60.     }
  61.  
  62.     if( rdargs = ReadArgs(Template, (LONG *)&Args, NULL) ) {
  63.         LockPubScreenList();
  64.         if( Args.def ) {
  65.             GetDefaultPubScreen(name);
  66.         }
  67.         else {
  68.             ULONG lock;
  69.             struct Screen *firstscreen, *thisscreen;
  70.  
  71.             lock = LockIBase(0);
  72.             firstscreen = IntuitionBase->FirstScreen;
  73.             UnlockIBase(lock);
  74.  
  75.             if( (firstscreen->Flags & SCREENTYPE)==PUBLICSCREEN ) {
  76.                 thisscreen = NULL;
  77.                 do {
  78.                     if( NextPubScreen(thisscreen, name)==NULL ) {
  79.                         GetDefaultPubScreen(name);
  80.                         rc = RETURN_WARN;
  81.                         break;
  82.                     }
  83.                     thisscreen = LockPubScreen(name);
  84.                     UnlockPubScreen(NULL, thisscreen);
  85.                 }
  86.                 while( thisscreen != firstscreen );
  87.             }
  88.             else {
  89.                 GetDefaultPubScreen(name);
  90.                 rc = RETURN_WARN;
  91.             }
  92.         }
  93.         UnlockPubScreenList();
  94.         FreeArgs(rdargs);
  95.  
  96.         PutStr(name); PutStr("\n");
  97.     }
  98.     else {
  99.         PrintFault(IoErr(), THIS_PROGRAM);
  100.         rc = RETURN_ERROR;
  101.     }
  102.     _exit(rc);
  103. }
  104.  
  105.